<!-- 
/*
 * @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");  
 * you may not use this file except in compliance with the License.  
 * You may obtain a copy of the License at  
 *     
 *     http://www.apache.org/licenses/LICENSE-2.0  
 *     
 * Unless required by applicable law or agreed to in writing, software  
 * distributed under the License is distributed on an "AS IS" BASIS,  
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
 * See the License for the specific language governing permissions and  
 * limitations under the License.
 */
 -->
 
<%@ page language="java" import="java.util.*"  pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="shortcut icon"  href="<%=basePath %>/favicon.ico" >
	<link rel="stylesheet" href="<%=basePath %>/library/js/bootstrap/css/bootstrap.min.css">
	<script src="<%=basePath %>/library/js/jquery-1.12.2.min.js"></script>
	<script src="<%=basePath %>/library/js/bootstrap/js/bootstrap.min.js"></script>
	<script src="<%=basePath %>/library/js/jsencrypt.min.js"></script>
	<title>微克机器人</title>
	<script type="text/javascript">

		$(function(){
			$("#loginMes").html(decodeURI(getQueryVariable("message")));
			$('#loginBtn').on('click', function () {
				loginSumit();
			});
			
	        $(document).keyup(function(){
	            if(event.keyCode==13){
	                loginSumit();
	            }
	        });
		});
		
		function loginSumit() {
			var $btn = $('#loginBtn').button('loading');
			if($("#pwd").val() != "") {
				$("#pwd").val(rsaEncrypt($("#pwd").val()));
			}
			$("#loginForm").submit();
		}
		
		function rsaEncrypt(data) {
		    var encrypt = new JSEncrypt();
		    encrypt.setPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCm83raeRgiS/FZfkzoxGKWDLREL8lS63S8JwJ6IYFIaRZjVSTV8xHHQUWB7F2qh1BbXg0LqAD8qqyYtIdNio8nksXcxlLhjvltw/iQ5EU1/kOg+ZpvUKWxRhjV+L+dN1mGGGS/JLRXEszdF4OxP7wTAaQvGVs+u6mwUFearrJYawIDAQAB");
		    var arr=Array();
			var arr1=Array();
			var str = "";
			var byteData = str2UTF8(data);

			if(byteData.length > 128) {
				var arr=Array();
			    var arr1=Array();
			    for(var i=0;i<data.length;i+=37){ //约定好的用37就算中文也不会超过长度
			    	arr.push(data.slice(i,i+37)); //slice比substring更好
			    }
			    for(var i in arr){
			    	arr1.push(encrypt.encrypt(arr[i]));
			    }
			    str=arr1.join(',');
			  } else {
			  	str = encrypt.encrypt(data);
			  }
			return str;
		}

		function str2UTF8(str){  
		    var bytes = new Array();   
		    var len,c;  
		    len = str.length;  
		    for(var i = 0; i < len; i++){  
		        c = str.charCodeAt(i);  
		        if(c >= 0x010000 && c <= 0x10FFFF){  
		            bytes.push(((c >> 18) & 0x07) | 0xF0);  
		            bytes.push(((c >> 12) & 0x3F) | 0x80);  
		            bytes.push(((c >> 6) & 0x3F) | 0x80);  
		            bytes.push((c & 0x3F) | 0x80);  
		        }else if(c >= 0x000800 && c <= 0x00FFFF){  
		            bytes.push(((c >> 12) & 0x0F) | 0xE0);  
		            bytes.push(((c >> 6) & 0x3F) | 0x80);  
		            bytes.push((c & 0x3F) | 0x80);  
		        }else if(c >= 0x000080 && c <= 0x0007FF){  
		            bytes.push(((c >> 6) & 0x1F) | 0xC0);  
		            bytes.push((c & 0x3F) | 0x80);  
		        }else{  
		            bytes.push(c & 0xFF);  
		        }  
		    }  
		    return bytes;  
		}
		
		function getQueryVariable(variable) {
		       var query = window.location.search.substring(1);
		       var vars = query.split("&");
		       for (var i=0;i<vars.length;i++) {
		               var pair = vars[i].split("=");
		               if(pair[0] == variable){return pair[1];}
		       }
		       return "";
		}
		
	</script>
</head>
<body>
	<div class="container">
		<form id="loginForm" class="form-signin" action="<%=basePath %>/login" method="post">
	        <div class="modal-dialog" style="margin-top: 15%;">
	            <div class="modal-content">
	                <div class="modal-header">
	                    <h4 class="modal-title">欢迎使用微克机器人</h4>
	                </div>
 	                
	                <div class="modal-body">
	                    
	                	<input type="hidden" name="userKey" value="test" placeholder="" autocomplete="off" class="form-control placeholder-no-fix">
	                	<div class="form-body">
				            <div class="form-group">
				                <label for="user" stype="display:inline;">帐号：</label>
				                <input type="text" name="account" class="form-control" id="user" value="" style="display:inline;width:200px;"autocomplete="off" />
				            </div>
				            <div class="form-group">
				                <label for="password" style="display:inline;">密码：</label>
				                <input id="pwd" name="pwd" type="password" class="form-control" id="password" value="" style="display:inline;width:200px;"autocomplete="off" />
				            </div>
	                    	<div class="form-group">
	                    		<label id="loginMes" class="label label-danger" stype="display:inline;"></label>
	                    		<button id="loginBtn" class="btn btn-primary pull-right" type="button">进入系统</button>
	                    		<br/>
	                    	</div>
	                    </div>
	                    	
	                </div>
<!--  	                 
	                <div class="modal-footer"></div>
-->
	            </div>
	        </div>
        </form>
	</div>            
</body>
</html>